/**
 * Created by WT-SUN on 2017/5/31.
 */
$(function () {
    var rId = $.getQueryParam('id');
    $('#rInfoTb').datagrid({
        rownumbers: true,//显示行号
        striped: true,
        fit: true,
        singleSelect: true,
        sortOrder: true,
        fitColumns: true,
        pagination: true,
        url:ROOT_PATH + '/threeSimultaneities/report/infoTb.shtml',
        queryParams: {
            sort: 'addTime',
            order: 'desc',
            monthReportId:rId
        },
        columns: [[
            {
                field: 'id',checkbox:true
            },
            {
                field: 'proName', title: '项目名称', width: 200,formatter: function (value, row, index) {
                return "<a href='javascript:void(0)' class='easyui-linkbutton text-primary' plain='true'   onclick='infodReport(\""+row.id+"\");'>"+row.proName+"</a>";
            }},
            {field: 'specialtyIdName', title: '专业分类', width: 100},
            {field: 'problemTypeIdName', title: '问题分类', width: 100},
            {field: 'problems', title: '问题描述', width: 200},
            {field: 'rectifyPlan', title: '整改方案', width: 100},
            {field: 'rectifyCondition', title: '整改情况', width: 100},
            {field: 'realName', title: '整改人', width: 100},
            {field: 'rectifyTime', title: '整改时间', width: 100},
            {field: 'rectifyStateId', title: '整改状态', width: 80,formatter: function (value, row, index) {
                return row.rectifyStateId=='1'?'已整改':'整改中';
            }}
        ]]
    });
    $('#thrInfoTb_add').on('click',function () {
        addInfoTb(rId);
    });
    $('#thrInfoTb_delete').on('click',function () {
        deleteInfoTb();
    });
    $('#thrInfoTb_submit').on('click',function () {
        editInfoTb(rId);
    });
});
function reLoadData() {
    $('#rInfoTb').datagrid('clearSelections');
    $("#rInfoTb").datagrid('reload', ROOT_PATH + '/threeSimultaneities/report/infoTb.shtml');
}
function addInfoTb(rId) {
    var title = '月报明细';
    var content = ROOT_PATH + '/threeSimultaneities/report/addInfo.shtml?resourceId=' + $.getQueryParam('resourceId')+'&rId='+rId;
    WindowManager.openLayer({
        type: 2,
        resize: false,
        title: title,
        area: ['1150px', '65%'],
        content: content,
        callBack:function(data){
            if(data){
                reLoadData();
            }
        }
    });
}
function deleteInfoTb() {
    var rows = $('#rInfoTb').datagrid('getSelections');

    if (rows.length == 0) {
        layer.alert("选择需要删除的行！");
        return;
    }
    var id = rows[0].id;
    layer.confirm('是否确定删除当前选中数据？', {
        btn: ['确定', '取消'] //按钮
    }, function () {
        $.ajax({
            type: 'post',
            url: ROOT_PATH + '/threeSimultaneities/report/deleteInfoReport.shtml',
            data: {id: id},
            dataType: "json",
            success: function (result) {
                if (result.success) {
                    $('#phyDataTb').datagrid('clearSelections');
                    reLoadData();
                    layer.msg('删除成功', {
                        icon: 1,
                        time: 1000
                    });
                }
                else {
                    layer.msg('删除失败', {
                        icon: 2,
                        time: 1000
                    });
                }
            }
        });
    });
}
function editInfoTb(rId) {
    $.ajax({
        type: 'post',
        url: ROOT_PATH + '/threeSimultaneities/report/updateReportState.shtml',
        data: {id: rId},
        dataType: "json",
        success: function (result) {
            if (result.success) {
                layer.msg('保存成功', {
                    icon: 1,
                    time: 1000 //2秒关闭（如果不配置，默认是3秒）
                }, function () {
                    WindowManager.closeLayer({
                        returnValue: true
                    });
                });
            }
            else {
                layer.msg('保存失败', {
                    icon: 2,
                    time: 1000
                });
            }
        }
    });
}
function infodReport(id) {
    var title = '月报明细';
    var content = ROOT_PATH + '/threeSimultaneities/report/reInfo.shtml?id='+id;
    parent.layer.open({
        type: 2,
        resize: false,
        title: title,
        area: ['1150px', '65%'],
        content: content
    });

    /* WindowManager.openLayer({
     type: 2,
     resize: false,
     title: title,
     area: ['1150px', '65%'],
     content: content
     });*/
}

